package org.kl.bf.utils;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.subject.WebSubject;

/**
 * shiro 工具类 
 * @author Qken
 * @date 2014年4月16日
 */
public class ShiroUtils {

	public static HttpSession getHttpSession() {
		ServletRequest request = ((WebSubject) SecurityUtils.getSubject())
				.getServletRequest();
		HttpSession httpSession = ((HttpServletRequest) request).getSession();
		return httpSession;
	}
	
	public static HttpServletRequest getHttpServletRequest(){
		return (HttpServletRequest) getServletRequest();
	}
	
	public static ServletRequest getServletRequest(){
		ServletRequest request = ((WebSubject) SecurityUtils.getSubject())
				.getServletRequest();
		return request;
	}
	
	public static ServletContext getServletContext(){
		return getHttpSession().getServletContext();
	}
}
